package com.example.carproviderbackstage.service.impl.dl.admin;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.carinterface.service.dl.admin.ContentService;
import com.example.carinterface.utils.ResultJson;
import com.example.carproviderbackstage.mapper.dl.admin.ContentMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private ContentMapper contentMapper;

    @Override
    public ResultJson<List<Map<String, Object>>> findAllBrand() {

        ResultJson<List<Map<String, Object>>> resultJson = new ResultJson<>();
        List<Map<String, Object>> list = contentMapper.findAllBrand();
        resultJson.setSuccess("查询成功", list);


        return resultJson;
    }

    @Override
    public ResultJson<String> addBrand(Map<String, Object> map) {
        ResultJson<String> resultJson = new ResultJson<>();
        int i = contentMapper.addBrand(map);
        if (i == 1) {
            resultJson.setSuccess("添加成功");
        } else {
            resultJson.setSuccess("添加失败");
        }

        return resultJson;
    }

    @Override
    public ResultJson<String> updateBrand(Map<String, Object> map) {
        ResultJson<String> resultJson = new ResultJson<>();
        int i = contentMapper.updateBrand(map);
        if (i == 1) {
            resultJson.setSuccess(" 修改成功");
        } else {
            resultJson.setSuccess("修改失败");
        }

        return resultJson;
    }

    @Override
    public ResultJson<List<Map<String, Object>>> findShop(Map<String,Object> map) {

        ResultJson<List<Map<String, Object>>> resultJson = new ResultJson<>();

        List<Map<String, Object>> list = contentMapper.findShop(map);

        resultJson.setSuccess("查询成功", list);

        return resultJson;
    }

    @Override
    public ResultJson<String> delShop(Integer id) {

        ResultJson<String> resultJson = new ResultJson<>();
       int i =  contentMapper.delShop(id);
       if (i==1){
           resultJson.setSuccess("删除成功");
       }else {
           resultJson.setSuccess("删除失败");
       }
        return resultJson;
    }

    @Override
    public ResultJson<String> updateShop(Map<String, Object> map) {

        ResultJson<String> resultJson = new ResultJson<>();
        int i =  contentMapper.updateShop(map);
        if (i==1){
            resultJson.setSuccess("修改成功");
        }else {
            resultJson.setSuccess("修改失败");
        }
        return resultJson;
    }

    @Override
    public ResultJson<String> addShop(Map<String, Object> map) {
       int i =  contentMapper.addShop(map);

        ResultJson<String> resultJson = new ResultJson<>();
       if (i==1){
           resultJson.setSuccess("添加店铺成功");
       }else {
           resultJson.setSuccess("添加店铺失败");
       }

        return resultJson;
    }
}
